package com.budwk.app.util.JsonToEntity;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;

import static com.budwk.app.util.JsonToEntity.VuePageGenerator.generateVuePage;

/**
 * @desc: 获取Java项目路径
 * @Author: laoschiang
 * @Date: 2023/11/29 21:42
 * @info:
 */

public class TestJsonToEntity {
    /**
     *  获取当前类的所在工程真实路径
     * @param clazz
     * @return {@link String}
     */
    public static String getPath(Class clazz){
        return clazz.getResource("").getPath().replace("target/classes","src/main/java")+File.separator+clazz.getSimpleName()+".java";
    }

    /**
     * 获取类加载的根路径
     * @param
     * @return {@link String}
     */
    public String getProjectPathUrl(){
        // 第一种：获取类加载的根路径   D:\git\daotie\daotie\target\classes
        File f = new File(this.getClass().getResource("/").getPath());
        System.out.println("获取类加载的根路径:"+this.getClass().getResource("/").getPath());
        System.out.println(f);

        // 获取当前类的所在工程路径; 如果不加“/”  获取当前类的加载目录  D:\git\daotie\daotie\target\classes\my
        File f2 = new File(this.getClass().getResource("").getPath());
        System.out.println("获取当前类的加载目录:"+this.getClass().getResource("").getPath());
        System.out.println(f2);

        // 第二种：获取项目路径    D:\git\daotie\daotie
        File directory = new File("");// 参数为空
        String courseFile = null;
        try {
            courseFile = directory.getCanonicalPath();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(courseFile);


        // 第三种：  file:/D:/git/daotie/daotie/target/classes/
        URL xmlpath = this.getClass().getClassLoader().getResource("");
        System.out.println(xmlpath);


        // 第四种： D:\git\daotie\daotie
        System.out.println(System.getProperty("user.dir"));
        /*
         * 结果： C:\Documents and Settings\Administrator\workspace\projectName
         * 获取当前工程路径
         */
        // 第五种：  获取所有的类路径 包括jar包的路径
        System.out.println(System.getProperty("java.class.path"));

        return null;
    }
    public static String GenerateDto(String clazz, String classDescription, String json){

        String getPath= "E:\\svn\\dfxy-shequ\\wk-mini\\src\\main\\java\\com\\budwk\\app\\sqfw\\dto\\";
        String fileName = clazz+".java";
        JsonToEntity jsonToEntity = new JsonToEntity();
        String dto= jsonToEntity.toEntityOrUpdateFile(clazz,classDescription,json);
        File file = new File(getPath, fileName);
        try (FileWriter writer = new FileWriter(file)) {
            writer.write(dto);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }

    public static String GenerateVue(String clazz, String classDescription, String json){

        String getPath= "E:\\svn\\dfxy-shequ\\wk-mini\\src\\main\\java\\com\\budwk\\app\\sqfw\\dto\\";
        String fileName = clazz+".vue";
        String vuePage = generateVuePage(json);
        System.out.println(vuePage);
        File file = new File(getPath, fileName);
        try (FileWriter writer = new FileWriter(file)) {
            writer.write(vuePage);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }

    public static void main(String[] args) {
       String dto= "{\n" +
                "  \"PlaceName\": \"场所名称\",\n" +
                "  \"PlaceAddress\": \"场所地址\",\n" +
                "  \"LegalPersonOrResponsiblePerson\": \"法人/负责人\",\n" +
                "  \"ContactNumber\": \"联系电话\",\n" +
                "  \"BusinessLicense\": \"营业执照\",\n" +
                "  \"PlaceType\": \"场所类型\",\n" +
                "  \"ViolationsOrResidents\": \"有无违规住人\",\n" +
                "  \"FlammableMaterials\": \"有无易燃可燃材料\",\n" +
                "  \"FireSafetyEducation\": \"有无消防宣传教育培训\",\n" +
                "  \"FireFacilities\": \"消防设施\",\n" +
                "  \"UseOfFireGas\": \"用火（气）\",\n" +
                "  \"UseOfFireElectricity\": \"用火（电）\",\n" +
                "  \"SelfInspectionRecords\": \"自查工作记录\",\n" +
                "  \"SecurityFacilities\": \"技防设施\",\n" +
                "  \"BuildingStructure\": \"房屋结构\",\n" +
                "  \"FireFacilityEquipment\": \"消防设施配备情况\",\n" +
                "  \"FireAndElectricityManagement\": \"用火用电管理情况\",\n" +
                "  \"Photos\": \"照片（至少上传门头照、签字照）\",\n" +
                "  \"Colleagues\": \"同行人员\",\n" +
                "  \"ResponsiblePersonSignature\": \"被检查单位负责人（签名）\",\n" +
                "  \"OrganizationalRulesAndRegulations\": \"组织领导规章制度\",\n" +
                "  \"WorkLog\": \"工作台账\",\n" +
                "  \"GasSupplyCompanySafetyTraining\": \"供气企业是否开展入户安检及安全培训\",\n" +
                "  \"ThirtySixQuestionsArray\": \"三十六个问题数组（1组，2组）\",\n" +
                "  \"CylinderStorageAfterClosing\": \"收市后气瓶存储地\",\n" +
                "  \"GasUsage\": \"燃气使用量\",\n" +
                "  \"GasBottleStorage\": \"燃气存瓶量\",\n" +
                "  \"GasSupplyCompanyName\": \"供气企业名称\",\n" +
                "  \"ComplianceOfGasStorage\": \"燃气存储地是否合规\",\n" +
                "  \"RectificationDate\": \"整改日期\",\n" +
                "  \"OtherFireHazardsOrIllegalActivities\": \"其他消防隐患或违法行为\",\n" +
                "  \"InspectionResults\": \"巡查结果\",\n" +
                "  \"SpecificResponsiblePersonIncludingStaff\": \"具体责任人（含工作人员）\",\n" +
                "  \"ContactPhoneNumber\": \"联系电话\",\n" +
                "  \"GasUsersCondition\": \"钢瓶、管道、灶具等燃气用户状况\",\n" +
                "  \"ExistenceOfSafetyHazards\": \"是否存在安全隐患\",\n" +
                "  \"Rectified\": \"是否已整改\",\n" +
                "  \"ProblemHazards\": \"问题隐患（第一组，第二组，第三组）\",\n" +
                "  \"RectificationMeasures\": \"整改措施\",\n" +
                "  \"RectificationProgress\": \"整改推进情况\",\n" +
                "  \"OnSiteWhichLines\": \"现场哪几条（第一组，第二组，第三组）\",\n" +
                "  \"LimitedPeriodWhichLines\": \"限期哪几条（第一组，第二组，第三组）\",\n" +
                "  \"OnSiteRectificationPhotos\": \"现场整改后照片\",\n" +
                "  \"OrganizationalInspectionsPeopleCount\": \"组织检查人次（前端根据同行人+自己）人数\",\n" +
                "  \"WeakElectricalLines\": \"弱电线路\",\n" +
                "  \"StrongElectricalLines\": \"强电线路\",\n" +
                "  \"EmergencySafetyHazards\": \"应急安全隐患\",\n" +
                "  \"BuildingArea\": \"建筑面积\",\n" +
                "  \"GeneralHazardsRectifiedQuantity\": \"一般隐患已整改数量\",\n" +
                "  \"IndependentFireControlRoom\": \"是否设有独立消防控制室\",\n" +
                "  \"MicroFireStationConstruction\": \"是否建设微型消防站\",\n" +
                "  \"PlaceApprovalByPublicSecurityFireDepartment\": \"场所是否经公安消防机构审批\",\n" +
                "  \"NumberOfRooms\": \"客房数(旅馆、饭店)\",\n" +
                "  \"NumberOfBeds\": \"床位数（医院、养老院、学校、幼儿园）\",\n" +
                "  \"NumberOfBuildings\": \"栋数（户数）\",\n" +
                "  \"BuildingHeight\": \"建筑高度\"\n" +
                "}";

        GenerateDto("FormSummaryNew","",dto);


    }

}

